package cn.yoyo.controller.adm;

import cn.yoyo.entity.BlogType;
import cn.yoyo.service.BlogTypeService;
import cn.yoyo.tools.RespJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("/api/adm/blogType")
public class AdmBlogTypeController {
    @Autowired
    BlogTypeService blogTypeService;

    @RequestMapping("/go2BlogTypeList")
    public String go2BlogType(){
        return "blog/typeList";
    }

    @RequestMapping("/add")
    @ResponseBody
    public Map<String,Object> add(@RequestBody BlogType blogType){
        System.out.println(blogType.toString());
        blogTypeService.add(blogType);
        return RespJson.pack(200,"添加成功",blogTypeService.findAll());
    }

    @RequestMapping("/update")
    @ResponseBody
    public Map<String,Object> update(@RequestBody BlogType blogType){
        System.out.println(blogType.toString());
        blogTypeService.update(blogType);
        return RespJson.pack(200,"修改成功",blogTypeService.findAll());
    }

    @RequestMapping("/deleteById/{id}")
    @ResponseBody
    public Map<String,Object> deleteById(@PathVariable("id")String blogtypeId){
        System.out.println(blogtypeId);
        blogTypeService.deleteById(blogtypeId);
        return RespJson.pack(200,"删除成功",blogTypeService.findAll());
    }

}
